package com.xm.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.xm.entity.Banners;
import com.xm.entity.Comdetail;
import com.xm.entity.Designer;
import com.xm.entity.Images;
import com.xm.uti.DBManager;
import com.xm.uti.QueryDataResult;

/**
 * 查询设计师方法持久层
 * 
 * @author kh
 *
 */
public class DesignerDaolmpl {
	// 查列表
	public ArrayList<Designer> getAllDesigner() {
		String sql = "select * from designer";// 注意后边的空格，sql查询语句
		System.out.println("执行的sql语句是" + sql);
		QueryDataResult execQuery = DBManager.executeQuery(sql);
		ArrayList<Designer> list = new ArrayList<Designer>();
		if (execQuery != null) {

			ResultSet rs = execQuery.rs;

			try {
				while (rs.next()) {
					Designer e = new Designer();
					e.setId(rs.getInt(1));
					e.setName(rs.getString("name"));
					e.setPosition(rs.getString("position"));
					e.setUrl(rs.getString("url"));
					list.add(e);
				}
			} catch (SQLException e) {
				e.printStackTrace();
			} finally {
				execQuery.close();
			}
		}
		System.out.println(list);

		return list;
	}
	/**
	 * 增
	 * 
	 * @param 
	 * @return
	 */
	public boolean addDesinger(Designer designer) {
		String sql = "insert into designer (name,position,url) values('" + designer.getName() + "','"
				+ designer.getPosition() + "','" + designer.getUrl() + "')";
		System.out.println("执行的sql语句是" + sql);
		int i = DBManager.executeUpdate(sql);
		if (i > 0) {
			return true;
		}
		return false;
	}
		/**
		 * 删除
		 * 
		 * @param emp
		 * @return
		 */
		public boolean delDesinger(int id) {
			String sql = "delete from designer where id = " + id;
			int i = DBManager.executeUpdate(sql);
			if (i > 0) {
				return true;
			}
			return false;
		}
		
		/**
		 * 修改
		 * 
		 * @param emp
		 * @return
		 */
		public boolean updDesinger(Designer designer) {
			String sql = "update designer set url='" + designer.getUrl() + "',position='" + designer.getPosition() + "',name='"
					+ designer.getName() +"' where id =" + designer.getId();
			int i = DBManager.executeUpdate(sql);
			if (i > 0) {
				return true;
			}
			return false;
		}
	

}
